<?php
class Marketing_AdminClassController extends Zendvn_Controller_Action{
	
	protected $_arrParam;
	protected $_currentController;
	protected $_actionMain;
	
	protected $_paginator = array(
									'itemCountPerPage' => 15,
									'pageRange' => 10,
									'currentPage' => 1
									);
	protected $_namespace;
	
	protected $_page = '';
	protected $_id_kh = '';
	
	public function init(){
		$this->_arrParam = $this->_request->getParams();
		$this->_currentController = '/' . $this->_arrParam['module'] . '/' . $this->_arrParam['controller'];
		$this->_actionMain = '/' . $this->_arrParam['module'] . '/'	. $this->_arrParam['controller'] . '/index';
		$this->_controllerMain = '/' . $this->_arrParam['module'] . '/'	. $this->_arrParam['controller']; //Duong dan cua Controller chinh
	
		$this->_namespace = $this->_arrParam['module'] . '-' . $this->_arrParam['controller'];
		$ssFilter = new Zend_Session_Namespace($this->_namespace);
		//Lay thong tin so phan tu tren mot trang
		if(isset($this->_arrParam['limitPage'])){
			$ssFilter->limitPage = $this->_request->getParam('limitPage');
			$this->_paginator['itemCountPerPage'] = $ssFilter->limitPage;
		}elseif(!empty($ssFilter->limitPage)){
			$this->_paginator['itemCountPerPage'] = $ssFilter->limitPage;
		}
		
		if(isset($this->_arrParam['page'])){
			$this->_paginator['currentPage'] = $this->_arrParam['page'];
			$this->_page = '/page/' . $this->_arrParam['page'];
		}
		
		if(!empty($this->_arrParam['id_kh'])){
			$this->_page .= '/id_kh/' . $this->_arrParam['id_kh'];
			$this->_id_kh = '/id_kh/' . $this->_arrParam['id_kh'];
		}
		
		$this->_arrParam['paginator'] = $this->_paginator;
		
		if(empty($ssFilter->col)){
			$ssFilter->keywords 	= '';
			$ssFilter->col 			= 'hd.ngayky';
			$ssFilter->order 		= 'DESC';
			$ssFilter->id_khoahoc	= 0;
			$ssFilter->id_lophoc	= 0;
			$ssFilter->blocks		= 0;
		}
		$this->_arrParam['ssFilter']['keywords'] 	= $ssFilter->keywords;
		$this->_arrParam['ssFilter']['col'] 		= $ssFilter->col;
		$this->_arrParam['ssFilter']['order'] 		= $ssFilter->order;
		$this->_arrParam['ssFilter']['id_khoahoc'] 	= $ssFilter->id_khoahoc;
		$this->_arrParam['ssFilter']['id_lophoc'] 	= $ssFilter->id_lophoc;
		$this->_arrParam['ssFilter']['blocks'] 		= $ssFilter->blocks;

		//Truyen ra ngoai view
		$this->view->arrParam = $this->_arrParam;
		$this->view->currentController = $this->_currentController;
		$this->view->actionMain = $this->_actionMain;
	
		$siteConfig = Zend_Registry::get('siteConfig');
		$template_path = TEMPLATE_PATH . "/admin/" . $siteConfig['template']['admin'];
		$this->loadTemplate($template_path, 'template.ini', 'customer');
	}

	public function indexAction(){
		//var_dump($this->_arrParam);die;
		$this->view->Title = 'Chăm sóc khách hàng :: Danh sách học viên theo lớp';
		$this->view->headTitle($this->view->Title, true);

		$tblDS = new Marketing_Model_Class();
		$this->view->Items = $tblDS->listItem($this->_arrParam, array('task'=>'admin-list'));

		$tblAjax = new Khachhang_Model_Ajax();
		$this->view->slbKhoahoc = $tblAjax->itemInSelectbox($this->_arrParam, array('task' => 'get-khoahoc'));
		$this->view->slbLopHoc = $tblAjax->itemInSelectbox(array('id_khoahoc' => $this->_arrParam['ssFilter']['id_khoahoc']), array('task' => 'get-lophoc'));
		
		$tblPhongBan = new Default_Model_Phongban();
		$this->view->slbPhongBan = $tblPhongBan->itemInSelectbox($this->_arrParam);
		
		$tblNhanVien = new Default_Model_Users();
		$this->view->slbNhanVien = $tblNhanVien->itemInSelectbox($this->_arrParam, array('task' => 'get-nhanvien'));
		
		$totalItem = $tblDS->countItem($this->_arrParam, array('task'=>'admin-list'));
		
		$paginator = new Zendvn_Paginator();
		$this->view->paginator = $paginator->createPaginator($totalItem, $this->_paginator);
	}
	
	public function recyclebinAction(){
		//var_dump($this->_arrParam);die;
		$this->view->Title = 'Hợp đồng đã xóa:: Danh sách';
		$this->view->headTitle($this->view->Title, true);
	
		$tblHopDong = new Hopdong_Model_Hopdong();
		$this->view->Items = $tblHopDong->listItem($this->_arrParam, array('task'=>'admin-recyclebin'));
	
		$tblAjax = new Khachhang_Model_Ajax();
		$this->view->slbKhoahoc = $tblAjax->itemInSelectbox($this->_arrParam, array('task' => 'get-khoahoc'));
		$this->view->slbLopHoc = $tblAjax->itemInSelectbox(array('id_khoahoc' => $this->_arrParam['ssFilter']['id_khoahoc']), array('task' => 'get-lophoc'));
	
		$tblPhongBan = new Default_Model_Phongban();
		$this->view->slbPhongBan = $tblPhongBan->itemInSelectbox($this->_arrParam);
	
		$tblNhanVien = new Default_Model_Users();
		$this->view->slbNhanVien = $tblNhanVien->itemInSelectbox($this->_arrParam, array('task' => 'get-nhanvien'));
	
		$totalItem = $tblHopDong->countItem($this->_arrParam, array('task'=>'admin-recyclebin'));
	
		$paginator = new Zendvn_Paginator();
		$this->view->paginator = $paginator->createPaginator($totalItem, $this->_paginator);
	}
	
	public function filterAction(){
		$ssFilter = new Zend_Session_Namespace($this->_namespace);
		
		if($this->_arrParam['type'] == 'search'){
			if($this->_arrParam['key'] == 1){
				$ssFilter->keywords = trim($this->_arrParam['keywords']);
			}else{
				$ssFilter->keywords = '';
			}
		}
		
		if($this->_arrParam['type'] == 'id_khoahoc'){
			$ssFilter->id_khoahoc = $this->_arrParam['id_khoahoc'];
			$ssFilter->id_lophoc = 0;
		}
		
		if($this->_arrParam['type'] == 'id_lophoc'){
			$ssFilter->id_lophoc = $this->_arrParam['id_lophoc'];
		}
	
		if($this->_arrParam['type'] == 'order'){
			$ssFilter->col = $this->_arrParam['col'];
			$ssFilter->order = $this->_arrParam['by'];
		}
		
		if($this->_arrParam['type'] == 'blocks'){
			$ssFilter->blocks = $this->_arrParam['blocks'];
		}
	
		$this->_redirect($this->_actionMain . $this->_id_kh);
		
		$this->_helper->viewRenderer->setNoRender();
	}
	
	public function addAction() {
		$this->view->Title = 'Hợp đồng :: Thêm';
		$this->view->headTitle($this->view->Title, true);

		$tblHopDong = new Hopdong_Model_Hopdong();
		
		$tblKhachhang = new Khachhang_Model_Item();
		$this->view->Khachhang = $tblKhachhang->getItem($this->_arrParam, array('task' => 'admin-info'));
		$this->_arrParam['khachhang'] = $this->view->Khachhang; 
		
		if($this->_request->isPost()){
			$validator = new Hopdong_Form_ValidateItem($this->_arrParam, array());
			if($validator->isError() == true) {
				$this->view->messageError = $validator->getMessageError();
				$this->view->Item = $validator->getData();
			} else {
				$arrParam = $validator->getData();

				$lastID = $tblHopDong->saveItem($this->_arrParam, array('task' => 'admin-add'));
				if(empty($this->_arrParam['type'])){
					$this->_redirect($this->_actionMain . '/save/ok' . $this->_page);
				}else{
					if($this->_arrParam['type'] == 'apply'){
						$this->_redirect($this->_controllerMain . '/edit/save/ok/id/' . $lastID . $this->_page);
					}
					if($this->_arrParam['type'] == 'new'){
						$this->_redirect($this->_controllerMain . '/add/save/ok' . $this->_page);
					}
				}
			}
		}
	}
	
	public function infoAction(){
		$this->view->Title = 'Hợp đồng :: Xem thông tin';
		$this->view->headTitle($this->view->Title, true);
		$tblHopDong = new Hopdong_Model_Hopdong();
		$this->view->Item = $tblHopDong->getItem($this->_arrParam,array('task'=>'admin-info'));
		
		$tblUser = new Default_Model_Users();
		$this->view->createdBy = $tblUser->getItem(array('id' => $this->view->Item['created_by']),array('task'=>'admin-info'));
		$this->view->modifiedBy = $tblUser->getItem(array('id' => $this->view->Item['modified_by']),array('task'=>'admin-info'));
		
	}
	
	public function editAction(){
		$this->view->Title = 'Học Viên:: Sửa Điểm';
		$this->view->headTitle($this->view->Title, true);
		
		$tblHocvien = new Marketing_Model_Class();
		$this->view->Item = $tblHocvien->getItem($this->_arrParam, array('task'=>'admin-edit'));
		//var_dump($this->view->Item );
		$tblKhachhang = new Khachhang_Model_Item();
		$this->view->Khachhang = $tblKhachhang->getItem(array('id_kh' => $this->view->Item['id_kh']), array('task' => 'admin-info'));
		//var_dump($this->view->Khachhang);
		//$this->_arrParam['khachhang'] = $this->view->Khachhang; 
		
		if($this->_request->isPost()){
			$validator = new Daotao_Form_ValidateItem($this->_arrParam, array());
			if($validator->isError() == true) {
				$this->view->messageError = $validator->getMessageError();
				$this->view->Item = $validator->getData();
			} else {
				$arrParam = $validator->getData();

				$lastID = $tblHocvien->saveItem($this->_arrParam, array('task' => 'admin-edit'));
				if(empty($this->_arrParam['type'])){
					$this->_redirect($this->_actionMain . '/save/ok' . $this->_page);
				}else{
					if($this->_arrParam['type'] == 'apply'){
						$this->_redirect($this->_controllerMain . '/edit/save/ok/id/' . $lastID . $this->_page);
					}
					if($this->_arrParam['type'] == 'new'){
						$this->_redirect($this->_controllerMain . '/add/save/ok' . $this->_page);
					}
				}
			}
		}
	}
	
	public function deleteAction(){
		$this->view->Title = 'Hợp đồng :: Xóa';
		$this->view->headTitle($this->view->Title, true);
		if($this->_request->isPost()){
			if(($this->_arrParam['type'] == 'multi-delete') && ($this->_arrParam['task'] == 'ok')){
				$tblHopDong = new Hopdong_Model_Hopdong();
				$tblHopDong->deleteItem($this->_arrParam, array('task'=>'admin-delete-muti'));
				$this->_redirect($this->_actionMain . $this->_page);
			}else
				if(!empty($this->_arrParam['id'])){
				$tblHopDong = new Hopdong_Model_Hopdong();
				$tblHopDong->deleteItem($this->_arrParam, array('task'=>'admin-delete'));
				$this->_redirect($this->_actionMain . $this->_page);
			}
		}
	}
	
	public function statusAction(){
		$tblHopDong = new Hopdong_Model_Hopdong();
		$tblHopDong->changeStatus($this->_arrParam);
		$this->_redirect($this->_actionMain . $this->_page);
		$this->_helper->viewRenderer->setNoRender();
	}
	
	public function sortAction(){
		if($this->_request->isPost()){
			$tblHopDong = new Hopdong_Model_Hopdong();
			$tblHopDong->sortItem($this->_arrParam, array('task'=>'admin-sort'));
			$this->_redirect($this->_actionMain . $this->_page);
		}
		$this->_helper->viewRenderer->setNoRender();
	}
	
	
	
	public function excelAction(){
	
		$ssFilter = $this->_arrParam['ssFilter'];
	
		$tblClb = new Marketing_Model_Class();
		$this->view->Items = $listKhachhangclb = $tblClb->listItem($this->_arrParam, array('task'=>'admin-excel'));
	
		$info = new Zendvn_System_Info();
		$userInfo = $info->getMemberInfo();
		/* echo "<pre>";
		 print_r($info->getMemberInfo());
		echo "</pre>"; */
	
		$this->_helper->layout->disableLayout();
		$this->_helper->viewRenderer->setNoRender();
	
		error_reporting(E_ALL);
		ini_set('display_errors', TRUE);
		ini_set('display_startup_errors', TRUE);
		date_default_timezone_set('Asia/Ho_Chi_Minh');
	
		if (PHP_SAPI == 'cli')
			die('This example should only be run from a Web Browser');
	
		/** Include PHPExcel */
		require_once SCRIPTS_PATH . '/phpexcel/PHPExcel.php';
	
		// Create new PHPExcel object
		$objPHPExcel = new PHPExcel();
	
		// Set document properties
		$objPHPExcel->getProperties()->setCreator($userInfo['user_name'])
		->setLastModifiedBy($userInfo['user_name'])
		->setTitle("Danh Sach Hoc Vien")
		->setSubject("Danh Sach Hoc Vien")
		->setDescription("Danh sach khach hang duoc xuat boi " . $userInfo['user_name'])
		->setKeywords($userInfo['user_name'])
		->setCategory($userInfo['user_name']);
	
		// Tiêu đề
		$objPHPExcel->getActiveSheet()->setCellValueExplicit('B2', 'DANH SÁCH KHÁCH HÀNG')->mergeCells('B2:G2');
		$objPHPExcel->getActiveSheet()->getStyle('B2')->getFont()->setSize(20)->setBold(true);
		$objPHPExcel->getActiveSheet()->getStyle('B2')->getFont()->getColor()->setARGB(PHPExcel_Style_Color::COLOR_BLUE);
		$objPHPExcel->getActiveSheet()->getStyle('B2')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER_CONTINUOUS);
	
		// Fillter
		$start = 4;
		$objPHPExcel->setActiveSheetIndex(0)
		->setCellValue('B'.$start, 'Ngày xuất: '.@date('d/m/Y h:i:s'))->mergeCells('B'.$start.':C'.$start);
		$objPHPExcel->setActiveSheetIndex(0)
		->setCellValue('D'.$start, 'Bởi: '.$userInfo['user_name'])->mergeCells('D'.$start.':E'.$start);
	
	
	
		// Tiêu đề
		$title = $start + 2;
		$objPHPExcel->getActiveSheet()->setCellValueExplicit('B'.$title, 'STT');
		$objPHPExcel->getActiveSheet()->getStyle('B'.$title)->getFont()->setBold(true);
		$objPHPExcel->getActiveSheet()->getStyle('B'.$title)->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_CENTER);
		$objPHPExcel->getActiveSheet()->getStyle('B'.$title)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
	
		$objPHPExcel->getActiveSheet()->setCellValueExplicit('C'.$title, 'Mã Học Viên');
		$objPHPExcel->getActiveSheet()->getStyle('C'.$title)->getFont()->setBold(true);
		$objPHPExcel->getActiveSheet()->getStyle('C'.$title)->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_CENTER);
		$objPHPExcel->getActiveSheet()->getStyle('C'.$title)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
	
		$objPHPExcel->getActiveSheet()->setCellValueExplicit('D'.$title, 'Họ và tên');
		$objPHPExcel->getActiveSheet()->getStyle('D'.$title)->getFont()->setBold(true);
		$objPHPExcel->getActiveSheet()->getStyle('D'.$title)->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_CENTER);
		$objPHPExcel->getActiveSheet()->getStyle('D'.$title)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
	
		$objPHPExcel->getActiveSheet()->setCellValueExplicit('E'.$title, 'Điểm đầu vào ');
		$objPHPExcel->getActiveSheet()->getStyle('E'.$title)->getFont()->setBold(true);
		$objPHPExcel->getActiveSheet()->getStyle('E'.$title)->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_CENTER);
		$objPHPExcel->getActiveSheet()->getStyle('E'.$title)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
	
		$objPHPExcel->getActiveSheet()->setCellValueExplicit('F'.$title, 'Điểm giữa kỳ');
		$objPHPExcel->getActiveSheet()->getStyle('F'.$title)->getFont()->setBold(true);
		$objPHPExcel->getActiveSheet()->getStyle('F'.$title)->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_CENTER);
		$objPHPExcel->getActiveSheet()->getStyle('F'.$title)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
	
		$objPHPExcel->getActiveSheet()->setCellValueExplicit('G'.$title, 'Điểm đầu ra');
		$objPHPExcel->getActiveSheet()->getStyle('G'.$title)->getFont()->setBold(true);
		$objPHPExcel->getActiveSheet()->getStyle('G'.$title)->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_CENTER);
		$objPHPExcel->getActiveSheet()->getStyle('G'.$title)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
	
		$objPHPExcel->getActiveSheet()->setCellValueExplicit('H'.$title, 'Điểm giáo viên');
		$objPHPExcel->getActiveSheet()->getStyle('H'.$title)->getFont()->setBold(true);
		$objPHPExcel->getActiveSheet()->getStyle('H'.$title)->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_CENTER);
		$objPHPExcel->getActiveSheet()->getStyle('H'.$title)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
	
		$objPHPExcel->getActiveSheet()->setCellValueExplicit('I'.$title, 'Điểm Coach');
		$objPHPExcel->getActiveSheet()->getStyle('I'.$title)->getFont()->setBold(true);
		$objPHPExcel->getActiveSheet()->getStyle('I'.$title)->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_CENTER);
		$objPHPExcel->getActiveSheet()->getStyle('I'.$title)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
		
		$objPHPExcel->getActiveSheet()->setCellValueExplicit('J'.$title, 'Điểm lớp học');
		$objPHPExcel->getActiveSheet()->getStyle('J'.$title)->getFont()->setBold(true);
		$objPHPExcel->getActiveSheet()->getStyle('J'.$title)->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_CENTER);
		$objPHPExcel->getActiveSheet()->getStyle('J'.$title)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
		
		$objPHPExcel->getActiveSheet()->setCellValueExplicit('K'.$title, 'Số buổi điểm danh');
		$objPHPExcel->getActiveSheet()->getStyle('K'.$title)->getFont()->setBold(true);
		$objPHPExcel->getActiveSheet()->getStyle('K'.$title)->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_CENTER);
		$objPHPExcel->getActiveSheet()->getStyle('K'.$title)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
		
		$objPHPExcel->getActiveSheet()->setCellValueExplicit('L'.$title, 'Tên Lớp');
		$objPHPExcel->getActiveSheet()->getStyle('L'.$title)->getFont()->setBold(true);
		$objPHPExcel->getActiveSheet()->getStyle('L'.$title)->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_CENTER);
		$objPHPExcel->getActiveSheet()->getStyle('L'.$title)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
		
	
	
	
		//Chieu cao cột title
		$objPHPExcel->getActiveSheet()->getRowDimension($title)->setRowHeight(20);
	
		// Chiều rộng cột
		$objPHPExcel->getActiveSheet()->getColumnDimension('C')->setWidth(30);
		$objPHPExcel->getActiveSheet()->getColumnDimension('D')->setWidth(20);
		$objPHPExcel->getActiveSheet()->getColumnDimension('E')->setWidth(35);
		$objPHPExcel->getActiveSheet()->getColumnDimension('F')->setWidth(35);
		$objPHPExcel->getActiveSheet()->getColumnDimension('G')->setWidth(15);
		$objPHPExcel->getActiveSheet()->getColumnDimension('H')->setWidth(35);
		$objPHPExcel->getActiveSheet()->getColumnDimension('I')->setWidth(25);
		$objPHPExcel->getActiveSheet()->getColumnDimension('J')->setWidth(25);
		$objPHPExcel->getActiveSheet()->getColumnDimension('K')->setWidth(25);
		$objPHPExcel->getActiveSheet()->getColumnDimension('L')->setWidth(25);
		//Lấy danh sach các thành viên
		if(count($listKhachhangclb) > 0){
			foreach ($listKhachhangclb AS $key => $val){
				$number = $title + $key + 1;
				$objPHPExcel->getActiveSheet()->setCellValueExplicit('B'.$number, $key + 1);
				$objPHPExcel->getActiveSheet()->getStyle('B'.$number)->getFont();
				$objPHPExcel->getActiveSheet()->getStyle('B'.$number)->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_CENTER);
				$objPHPExcel->getActiveSheet()->getStyle('B'.$number)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
	
				$objPHPExcel->getActiveSheet()->setCellValueExplicit('C'.$number, $val['khachhang_code']);
				$objPHPExcel->getActiveSheet()->getStyle('C'.$number)->getFont();
				$objPHPExcel->getActiveSheet()->getStyle('C'.$number)->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_CENTER);
				$objPHPExcel->getActiveSheet()->getStyle('C'.$number)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_LEFT);
	
				$objPHPExcel->getActiveSheet()->setCellValueExplicit('D'.$number, $val['khachhang_name']);
				$objPHPExcel->getActiveSheet()->getStyle('D'.$number)->getFont();
				$objPHPExcel->getActiveSheet()->getStyle('D'.$number)->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_CENTER);
				$objPHPExcel->getActiveSheet()->getStyle('D'.$number)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_LEFT);
	
				$objPHPExcel->getActiveSheet()->setCellValueExplicit('E'.$number, $val['diemdauvao']);
				$objPHPExcel->getActiveSheet()->getStyle('E'.$number)->getFont();
				$objPHPExcel->getActiveSheet()->getStyle('E'.$number)->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_CENTER);
				$objPHPExcel->getActiveSheet()->getStyle('E'.$number)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_LEFT);
	
				$objPHPExcel->getActiveSheet()->setCellValueExplicit('F'.$number, $val['diemdaura']);
				$objPHPExcel->getActiveSheet()->getStyle('F'.$number)->getFont();
				$objPHPExcel->getActiveSheet()->getStyle('F'.$number)->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_CENTER);
				$objPHPExcel->getActiveSheet()->getStyle('F'.$number)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_LEFT);
	
				$objPHPExcel->getActiveSheet()->setCellValueExplicit('G'.$number, $val['diemdaura']);
				$objPHPExcel->getActiveSheet()->getStyle('G'.$number)->getFont();
				$objPHPExcel->getActiveSheet()->getStyle('G'.$number)->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_CENTER);
				$objPHPExcel->getActiveSheet()->getStyle('G'.$number)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
	
				$objPHPExcel->getActiveSheet()->setCellValueExplicit('H'.$number, $val['diemgiaovien']);
				$objPHPExcel->getActiveSheet()->getStyle('H'.$number)->getFont();
				$objPHPExcel->getActiveSheet()->getStyle('H'.$number)->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_CENTER);
				$objPHPExcel->getActiveSheet()->getStyle('H'.$number)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_LEFT);
	
				$objPHPExcel->getActiveSheet()->setCellValueExplicit('I'.$number, $val['diemcoach']);
				$objPHPExcel->getActiveSheet()->getStyle('I'.$number)->getFont();
				$objPHPExcel->getActiveSheet()->getStyle('I'.$number)->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_CENTER);
				$objPHPExcel->getActiveSheet()->getStyle('I'.$number)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_RIGHT);
				
				
				$objPHPExcel->getActiveSheet()->setCellValueExplicit('J'.$number, $val['diemlophoc']);
				$objPHPExcel->getActiveSheet()->getStyle('J'.$number)->getFont();
				$objPHPExcel->getActiveSheet()->getStyle('J'.$number)->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_CENTER);
				$objPHPExcel->getActiveSheet()->getStyle('J'.$number)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_RIGHT);
				
				$objPHPExcel->getActiveSheet()->setCellValueExplicit('K'.$number, $val['sobuoidiemdanh']);
				$objPHPExcel->getActiveSheet()->getStyle('K'.$number)->getFont();
				$objPHPExcel->getActiveSheet()->getStyle('K'.$number)->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_CENTER);
				$objPHPExcel->getActiveSheet()->getStyle('K'.$number)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_RIGHT);
				
				$objPHPExcel->getActiveSheet()->setCellValueExplicit('L'.$number, $val['lophoc_name']);
				$objPHPExcel->getActiveSheet()->getStyle('L'.$number)->getFont();
				$objPHPExcel->getActiveSheet()->getStyle('L'.$number)->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_CENTER);
				$objPHPExcel->getActiveSheet()->getStyle('L'.$number)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_RIGHT);
	
	
	
	
			}
		}
	
		// Rename worksheet
		//$objPHPExcel->getActiveSheet()->setTitle('Simple');
	
		// Set active sheet index to the first sheet, so Excel opens this as the first sheet
		$objPHPExcel->setActiveSheetIndex(0);
	
	
		// Redirect output to a client’s web browser (Excel5)
		header('Content-Type: application/vnd.ms-excel');
		header('Content-Disposition: attachment;filename="'.$userInfo['user_name'].'_'.@date('d_m_Y').'.xls"');
		header('Cache-Control: max-age=0');
	
		$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
		$objWriter->save('php://output');
		exit;
	
	}

}



